package com.cskaoyan;

import com.cskaoyan.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PrepareStatementDemo {

    public static void main(String[] args) throws SQLException {

        // 获取连接
        Connection connection = JDBCUtils.getConnection();

        // 获取PrepareStatement
        PreparedStatement preparedStatement = connection.prepareStatement("insert into user values (?,?,?,?)");

        // 设置参数
        preparedStatement.setInt(1,5);
        preparedStatement.setString(2,"高圆圆");
        preparedStatement.setString(3,"女神");
        preparedStatement.setString(4,"yyds");

        // 执行SQL语句
        int affectedRows = preparedStatement.executeUpdate();

        System.out.println(affectedRows);

        // 关闭资源
        JDBCUtils.closeResources(connection,preparedStatement,null);
    }
}
